﻿<script>
    function roundFun(numberRound, roundDigit) //四舍五入，保留位数为roundDigit
    {
        if (numberRound >= 0) {
            var tempNumber = parseInt((numberRound * Math.pow(10, roundDigit) + 0.5)) / Math.pow(10, roundDigit);
            return tempNumber;
        } else {
            numberRound1 = -numberRound
            var tempNumber = parseInt((numberRound1 * Math.pow(10, roundDigit) + 0.5)) / Math.pow(10, roundDigit);
            return -tempNumber;
        }
    }
    $(document).ready(function () {
        var stationid = "";
        if (PPSForm.IsFormPrint() != true) {
            stationid = PPSForm.GetStation().id;
            //设置样式
            $(":text,textarea").each(function () {
                $(this).css("border", "0");
                $(this).css("background-color", "transparent");
            });
            //设置场站
            $("#sf_fkcz").val(PPSForm.GetStation().text);
            $("#sf_station_bt").html("放空记录(" + PPSForm.GetStation().text + ")");
            //获取时间
            var date = PPSForm.GetDataDate();
            var myDate = new Date();
            //填写时间
            $("#sf_sj").val(date + " " + myDate.getHours() + ":" + myDate.getMinutes());
            //计算
            $("input[id^='sf_fkqyl'],input[id^='sf_fkhyl'],input[id^='sf_fkqwd'],input[id^='sf_fkhwd'],input[id^='sf_fkgr'],input[id^='sf_ysyz'],input[id^='sf_ysyzh']").keyup(function () {
                Calculate();
            })
            //压缩机编号
            $.ajax({
                type: "GET",
                url: PPSForm.BaseURL + "StaticFormHandler.ashx?type=2&StationID=" + PPSForm.GetStation().id + "&CurrentUserOUID=" + PPSForm.GetCurrentUserOUID(),
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#sf_ysjbh").combobox({
                        valueField: 'id',
                        textField: 'text',
                        data: data
                    });
                    var data = $('#sf_ysjbh').combobox('getData');
                    if (data.length > 0) {
                        $('#sf_ysjbh').combobox('select', data[0].id);
                    }
                }
            });
            //选择放空类型
            $("input[id^='sf_fklx']").each(function () {
                $(this).combobox({
                    onSelect: function (param) {
                        if (param.text == "紧急放空") {
                            $("#sf_fkl").removeAttr("disabled");
                            $("#sf_ysyz").removeAttr("disabled");
                            $("#sf_ysyzh").removeAttr("disabled");
                            $("#jsq").hide();
                            $("#jsh").hide();
                            $("#ysjbh").hide();
                            $("#sf_ysjbh").hide();
                        } else if (param.text == "压缩机吹扫放空" || param.text == "压缩机停机放空") {
                            $("#ysjbh").show();
                            //显示计算按钮
                            $("#jsq").show();
                            $("#jsh").show();
                        } else {
                            //显示计算按钮
                            $("#jsq").show();
                            $("#jsh").show();
                            $("#ysjbh").hide();
                        }
                    }
                });
            });
        } else {
            stationid = $('#hidFormStationID').val();
            $("#sf_station_bt").html("放空记录(" + $('#hidFormStationText').val() + ")");
            $("#jsbk").hide();
            $("#TableBody").css("margin-bottom", "100px");
        }
        //地区公司
        $.ajax({
            type: "GET",
            url: PPSForm.BaseURL + "GetAreaOrganizationName.ashx?StationID=" + stationid,
            async: false,
            success: function (data) {
                $("#sf_qzfxbg_kh").html(data);
                $("#sf_cydw").val(data);
                $("#sf_cydw_bc").val(data);
            }
        });

        //设置表单值
        PPSForm.SetFormItemValue();
    });
    function js(qh) {
        var p;
        var t;
        if (qh == 'q') {
            p = $("#sf_fkqyl").val() == '' ? '0' : $("#sf_fkqyl").val();
            t = $("#sf_fkqwd").val() == '' ? '0' : $("#sf_fkqwd").val();
        } else if (qh == "h") {
            p = $("#sf_fkhyl").val() == '' ? '0' : $("#sf_fkhyl").val();
            t = $("#sf_fkhwd").val() == '' ? '0' : $("#sf_fkhwd").val();
        } else {
            p = "0.101325";
            t = "20";
        }
        //var myDate = new Date();
        //var Dtime = myDate.toLocaleDateString() + " " + myDate.getHours() + ":" + myDate.getMinutes();
        var oWnd = SelfRadOpen("../ProfessionalCalculate/CompressibilityFactorCalculateTool.aspx?action=result&qh=" + qh + "&p=" + p + "&t=" + t + "&stationId=" + PPSForm.GetStation().id + "&dtime=" + $("#ctl00_ContentPlaceHolder1_RadDatePickerDate_dateInput").val() + " 08:00", null, "500", "650");
        oWnd.add_close(OnClientClose);
    }
    function Calculate() {
        var fkqyl = parseFloat($("#sf_fkqyl").val() == '' ? '0' : $("#sf_fkqyl").val());
        var fkhyl = parseFloat($("#sf_fkhyl").val() == '' ? '0' : $("#sf_fkhyl").val());
        var fkqwd = parseFloat($("#sf_fkqwd").val() == '' ? '0' : $("#sf_fkqwd").val());
        var fkhwd = parseFloat($("#sf_fkhwd").val() == '' ? '0' : $("#sf_fkhwd").val());
        var fkqysyz = parseFloat($("#sf_ysyz").val() == '' ? '0' : $("#sf_ysyz").val());
        var fkhysyz = parseFloat($("#sf_ysyzh").val() == '' ? '0' : $("#sf_ysyzh").val());

        var z0 = parseFloat($("#sf_ysyz_bk").val() == '' ? '0' : $("#sf_ysyz_bk").val());
        var p0 = parseFloat(0.101325);
        var t0 = parseFloat(20 + 273.15);
        var v = parseFloat($("#sf_fkgr").val() == '' ? '0' : $("#sf_fkgr").val());

        var v01 = (fkqyl * v * z0 * t0) / (fkqysyz * (fkqwd + 273.15) * p0);
        var v02 = (fkhyl * v * z0 * t0) / (fkhysyz * (fkhwd + 273.15) * p0);
        var result = 0;
        if (v01 == 'Infinity' || v01 == 'NaN' || v02 == 'Infinity' || v02 == 'NaN') {
            result = 0;
        } else {
            result = v01 - v02;
        }
        $("#sf_fkl").val(roundFun(result, 0));
        if ($("#sf_fkl").val() == 'NaN') {
            $("#sf_fkl").val(0)
        }
    }
    function OnClientClose(oWnd, args) {
        //get the transferred arguments
        var arg = args.get_argument();
        if (arg) {
            var qh = arg.split(",")[1];
            var ysyz = arg.split(",")[0];
            if (qh == "q") {
                $("#sf_ysyz").val(ysyz);
                Calculate();
            } else if (qh == "h") {
                $("#sf_ysyzh").val(ysyz);
                Calculate();
            } else if (qh == "bk") {
                $("#sf_ysyz_bk").val(ysyz);
                Calculate();
            }
        }
    }
    function DateTimeConverter() {

    }
    //非空验证
    function HtmlVerifyData() {
        var message = "";
        var message2 = "";
        var arr = ['sf_pcbh^放空设备及编号', 'sf_fkcz^场站名称', 'sf_sj^日期', 'sf_fkgr^放空管容', 'sf_ysyz_bk^标况下压缩因子', 'sf_fkqyl^放空前压力', 'sf_fkhyl^放空后压力', 'sf_fkqwd^放空前温度', 'sf_fkhwd^放空后温度', 'sf_fkl^放空量', 'sf_fkyy^放空原因'];
        $(arr).each(function () {
            var ID = this.split('^')[0];
            var Name = this.split('^')[1];
            if ($("#" + ID).val() == '') {
                message = message + Name + ",";
            }
        });
        var combox = ['sf_fklx^放空类型', 'sf_fkqtzl^放空气体种类', 'sf_fkqssj^放空起始时间', 'sf_fkjssj^放空结束时间'];
        $(combox).each(function () {
            var cid = this.split('^')[0];
            var cname = this.split('^')[1];
            if ($("#" + cid).combobox('getValue') == '') {
                message = message + cname + ",";
            }

        });

        var dateTimepatter = /2\d{3}.\d{1,2}.\d{1,2}.?\s\d{2}:\d{2}/
        var sf_fkqssjValue = $("#sf_fkqssj").combobox('getValue');
        var sf_fkjssjValue = $("#sf_fkjssj").combobox('getValue');
        if (!dateTimepatter.test(sf_fkqssjValue)) {
            alert('放空起始时间 不是时间格式');
            return false;
        }
        if (!dateTimepatter.test(sf_fkjssjValue)) {
            alert('放空结束时间 不是时间格式');
            return false;
        }

        if (message != "") {
            alert("以下表单项不允许为空：" + message.substring(0, message.length - 1));
            return false;
        } else {
            return true;
        }

    }
</script>
<table width="100%" border="0">
    <tr>
        <td style="height:20px"></td>
    </tr>
    <tr>
        <td class="TableHead">
            <label id="sf_qzfxbg_kh" />
        </td>
    </tr>
    <tr>
        <td class="TableHead">
            <label id="sf_station_bt">
            </label>
        </td>
    </tr>
</table>
<br />
<table width="100%" class="staticTable" id="TableBody">
    <tr>
        <td width="20%">
            场站名称：
            </span>
        </td>
        <td class="input">
            <input datatype="2" length="50" readonly="true" type="text" id="sf_fkcz" />
        </td>
        <td width="10%">
            日期：
        </td>
        <td colspan="3" class="input">
            <input datatype="2" length="50" readonly="true" type="text" id="sf_sj" />
        </td>
    </tr>
    <tr>
        <td>
            放空类型：
        </td>
        <td colspan="5">
            <input datatype="2" length="50" type="text" id="sf_fklx" formula="[9935:DIC=#easyui-combobox]" class="easyui-combobox" />
        </td>
    </tr>
    <tr>
        <td>
            放空设备及编号：
        </td>
        <td colspan="5">
            <input datatype="2" length="50" type="text" id="sf_pcbh" />
        </td>
    </tr>
    <tr id="ysjbh" style="display:none">
        <td>
            压缩机编号：
        </td>
        <td colspan="5">
            <input datatype="2" length="50" type="text" id="sf_ysjbh" class="easyui-combobox" />
        </td>
    </tr>
    <tr>
        <td>
            放空气体种类：
        </td>
        <td colspan="5">
            <input datatype="2" length="50" type="text" id="sf_fkqtzl" formula="[9984:DIC=#easyui-combobox]" class="easyui-combobox" />
        </td>
    </tr>
    <tr>
        <td>
            放空起始时间：
        </td>
        <td colspan="5">
            <input datatype="2" length="" type="text" class="easyui-datetimebox" id="sf_fkqssj" />
        </td>
    </tr>
    <tr>
        <td>
            放空结束时间：
        </td>
        <td colspan="5">
            <input datatype="2" length="" type="text" class="easyui-datetimebox" id="sf_fkjssj" />
        </td>
    </tr>
    <tr>
        <td width="15%">
            放空管容：
        </td>
        <td width="30%">
            <input datatype="1" decimaldigits="4" type="text" id="sf_fkgr" />
        </td>
        <td style="text-align:left">
            m
            <sup>
                3
            </sup>
        </td>
        <td width="20%">
            标况压缩因子：
        </td>
        <td width="30%">
            <input datatype="1" decimaldigits="3" type="text" id="sf_ysyz_bk" />
        </td>
        <td>
            <input type="button" onclick="js('bk');" id="jsbk" value="计算" />
        </td>
    </tr>
    <tr>
        <td>
            放空前压力：
        </td>
        <td>
            <input datatype="1" decimaldigits="2" type="text" id="sf_fkqyl" />
        </td>
        <td width="5%">
            Mpa
        </td>
        <td>
            放空后压力：
        </td>
        <td>
            <input datatype="1" decimaldigits="2" type="text" id="sf_fkhyl" />
        </td>
        <td width="5%">
            Mpa
        </td>
    </tr>
    <tr>
        <td>
            放空前温度：
        </td>
        <td>
            <input datatype="1" decimaldigits="2" type="text" id="sf_fkqwd" />
        </td>
        <td>
            ℃
        </td>
        <td>
            放空后温度：
        </td>
        <td>
            <input datatype="1" decimaldigits="2" type="text" id="sf_fkhwd" />
        </td>
        <td>
            ℃
        </td>
    </tr>
    <tr>
        <td>
            放空前压缩因子：
        </td>
        <td>
            <input datatype="1" decimaldigits="4" type="text" id="sf_ysyz" />
        </td>
        <td>
            <input type="button" style="display:none" onclick="js('q');" id="jsq" value="计算" />
        </td>
        <td>
            放空后压缩因子：
        </td>
        <td>
            <input datatype="1" decimaldigits="4" type="text" id="sf_ysyzh" />
        </td>
        <td>
            <input type="button" style="display:none" onclick="js('h');" id="jsh" value="计算" />
        </td>
    </tr>
    <tr>
        <td>
            放空量：
        </td>
        <td>
            <input type="text" id="sf_fkl" formula="[73870:ES=00000000-0000-0000-0000-000000000000^EL=00000000-0000-0000-0000-000000000000^AGG=]<D-1|15:DD|15>" sformula="[73870:ES=00000000-0000-0000-0000-000000000000^EL=00000000-0000-0000-0000-000000000000^AGG=]<DD>"
                   datatype="1" decimaldigits="0" />
        </td>
        <td style="text-align:left" colspan="4">
            Nm
            <sup>
                3
            </sup>
        </td>
    </tr>
    <tr>
        <td>
            放空原因：
        </td>
        <td colspan="5">
            <input datatype="2" length="50" type="text" id="sf_fkyy" />
        </td>
    </tr>
    <tr>
        <td>
            备注：
        </td>
        <td colspan="5">
            <textarea id="sf_D10" rows="5" style="overflow-y:hidden ; width: 100%;"></textarea>
        </td>
    </tr>
</table>